<template>
  <div class="user-settings-page">
    <div class="settings-sidebar">
      <div class="icon-item" :class="{ active: currentPath === '/' }" @click="navigateTo('/')">
        <img src="../assets/icons/首页.svg" alt="首页" />
      </div>
       <div class="icon-item" :class="{ active: currentPath === '/user-settings' }" @click="navigateTo('/user-settings')">
        <img src="../assets/icons/个人.svg" alt="个人" />
      </div>
    </div>

    <div class="settings-content">
      <h1 class="page-title">个人中心</h1>
      <div class="form-container">
        <div class="form-grid">
          <!-- Left Column -->
          <div class="form-column">
            <div class="form-group">
              <label>手机号</label>
              <input type="text" v-model="userInfo.phone" />
            </div>
            <div class="form-group">
              <label>昵称</label>
              <input type="text" v-model="userInfo.nickname" />
            </div>
            <div class="form-group bio-group">
              <label>简介</label>
              <textarea v-model="userInfo.introduction"></textarea>
            </div>
          </div>

          <!-- Right Column -->
          <div class="form-column">
            <div class="avatar-group">
              <div class="avatar-preview">
                <img v-if="userInfo.avatar" :src="userInfo.avatar" alt="用户头像" />
                 <img v-else src="https://images.unsplash.com/photo-1502672260266-1c1ef2d93688?w=400" alt="默认头像"/>
              </div>
              <div class="avatar-uploader">
                <div class="upload-box">
                  <span class="plus-icon">+</span>
                  <span class="upload-text">上传图片</span>
                </div>
                <p class="upload-hint">只支持.jpg .png格式</p>
              </div>
            </div>
            <div class="form-group email-group">
              <label>邮箱</label>
              <input type="email" v-model="userInfo.email" />
            </div>
             <button class="change-password-btn" @click="showPasswordDialog = true">修改密码</button>
          </div>
        </div>

        <div class="submit-area">
          <button class="submit-btn">提交</button>
        </div>
      </div>
    </div>
    
    <!-- 修改密码弹窗 -->
    <div class="password-dialog-overlay" v-if="showPasswordDialog" @click="closePasswordDialog">
      <div class="password-dialog" @click.stop>
        <div class="dialog-header">
          <div class="dialog-title">修改密码</div>
          <div class="close-btn" @click="closePasswordDialog">×</div>
        </div>
        <div class="dialog-body">
          <div class="dialog-form-group">
            <label>旧密码</label>
            <input type="password" v-model="passwordForm.oldPassword" placeholder="请输入" />
          </div>
          <div class="dialog-form-group">
            <label>新密码</label>
            <input type="password" v-model="passwordForm.newPassword" placeholder="请输入" />
          </div>
          <div class="dialog-form-group">
            <label>确认新密码</label>
            <input type="password" v-model="passwordForm.confirmPassword" placeholder="请输入" />
          </div>
          <button class="confirm-btn" @click="changePassword">确认</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, reactive, computed } from 'vue';
import { useRouter, useRoute } from 'vue-router';

export default {
  name: 'UserSettings',
  setup() {
    const router = useRouter();
    const route = useRoute();
    const showPasswordDialog = ref(false);

    const currentPath = computed(() => route.path);
    
    const userInfo = reactive({
      phone: '1234567',
      nickname: '1234567',
      avatar: '',
      introduction: '1234567',
      email: '1234567'
    });
    
    const passwordForm = reactive({
      oldPassword: '',
      newPassword: '',
      confirmPassword: ''
    });

    const navigateTo = (path) => {
      router.push(path);
    };
    
    const closePasswordDialog = () => {
      showPasswordDialog.value = false;
    };
    
    const changePassword = () => {
      if (passwordForm.newPassword !== passwordForm.confirmPassword) {
        alert('两次输入的密码不一致');
        return;
      }
      console.log('修改密码：', passwordForm);
      closePasswordDialog();
    };
    
    return {
      userInfo,
      showPasswordDialog,
      passwordForm,
      closePasswordDialog,
      changePassword,
      navigateTo,
      currentPath
    };
  }
};
</script>

<style scoped>
.user-settings-page {
  display: flex;
  background-color: #f7f8fa;
  min-height: 100vh;
}

.settings-sidebar {
  width: 80px;
  background-color: #EFEFEF;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 50px;
  gap: 30px;
}

.icon-item {
  width: 40px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.icon-item img {
  width: 24px;
  height: 24px;
  opacity: 0.6;
}

.icon-item.active {
  background-color: #fff;
  border-radius: 8px;
}

.icon-item.active img {
  opacity: 1;
}

.settings-content {
  flex: 1;
  padding: 40px 60px;
}

.page-title {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 30px;
}

.form-container {
  background-color: #ffffff;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 60px;
}

.form-column {
  display: flex;
  flex-direction: column;
}

.form-group {
  margin-bottom: 25px;
}

.form-group label {
  display: block;
  font-size: 14px;
  color: #606266;
  margin-bottom: 8px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #dcdfe6;
  border-radius: 8px;
  font-size: 14px;
}

.bio-group {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.bio-group textarea {
  flex-grow: 1;
  resize: none;
}

.avatar-group {
  display: flex;
  gap: 20px;
  margin-bottom: 25px;
}

.avatar-preview {
  width: 140px;
  height: 140px;
  border-radius: 12px;
  overflow: hidden;
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-uploader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.upload-box {
  width: 140px;
  height: 140px;
  border: 2px dashed #dcdfe6;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.plus-icon {
  font-size: 36px;
  color: #c0c4cc;
}

.upload-text {
  font-size: 14px;
  color: #606266;
}

.upload-hint {
  font-size: 12px;
  color: #909399;
  margin-top: 8px;
}

.email-group {
  margin-bottom: 20px;
}

.change-password-btn {
  align-self: flex-start;
  background-color: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 8px 20px;
  cursor: pointer;
}

.submit-area {
  margin-top: 40px;
  text-align: center;
}

.submit-btn {
  background-color: #DCCBBA;
  color: white;
  border: none;
  border-radius: 25px;
  padding: 12px 40px;
  font-size: 16px;
  cursor: pointer;
}

/* Password Dialog Styles - kept from previous version */
.password-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.password-dialog {
  width: 400px;
  background: linear-gradient(to right, #BCCDDA, #BCCDDA);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #e4e7ed;
}

.dialog-title {
  font-size: 16px;
  font-weight: 500;
}

.close-btn {
  font-size: 20px;
  cursor: pointer;
}

.dialog-body {
  padding: 20px;
}

.dialog-form-group {
  margin-bottom: 15px;
}

.dialog-form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
}

.dialog-form-group input {
  width: 100%;
  padding: 10px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  font-size: 14px;
}

.confirm-btn {
  width: 100%;
  background: linear-gradient(to right, #DCCBBA, #DCCBBA);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 10px 0;
  font-size: 16px;
  cursor: pointer;
  margin-top: 10px;
}
</style> 